<template>
  <div class="add_receipt_task">
    <el-form class="form" :model="addForm" :rules="rules" ref="addForm" label-width="20%">
      <el-form-item label="主办方" prop="orgid" style="clear:both">
        <el-select v-model="addForm.orgid" placeholder="请选择主办方" class="inline" clearable filterable>
          <el-option v-for="item in addForm.orgsels" :key="item.orgid" :label="item.trueid + '_' + item.orgname"
            :value="item.trueid">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item class="form_item" label="收鸽公告标题">
        <el-input v-model="addForm.name" placeholder="请输入标题" type="text" clearable></el-input>
      </el-form-item>
      <el-form-item class="form_item" :label="$t('receipt.URL')" prop="url">
        <el-input v-model="addForm.url" :placeholder="$t('tips.ENTER.URL')" type="textarea" :rows="3"
          clearable></el-input>
      </el-form-item>
      <el-form-item class="form_item" label="自动抓取">
        <el-col :span="3" class="hori-cond">
          <el-switch v-model="addForm.status" :active-value="1" :inactive-value="0"></el-switch>
        </el-col>
        <el-col :span="9">
          <el-date-picker style="width: 150px;" v-model="addForm.endtime" value-format="yyyy-MM-dd" type="date"
            placeholder="选择日期">
          </el-date-picker>
        </el-col>
        <el-col :span="6">
          <el-input v-model.number="addForm.hour1" type="text">
            <template slot="append">点至</template>
          </el-input>
        </el-col>
        <el-col :span="6">
          <el-input v-model.number="addForm.hour2" type="text">
            <template slot="append">点</template>
          </el-input>
        </el-col>
      </el-form-item>
      <el-form-item class="form_item" label="自动上报">
        <el-switch v-model="addForm.reportstatus" :active-value="1" :inactive-value="0"></el-switch>
      </el-form-item>
    </el-form>
    <div class="footer">
      <el-button class="cancel_button" @click="cancel">{{$t("common.CANCEL")}}</el-button>
      <el-button class="confirm_button" @click="addSubmit()">{{$t("common.CONFIRM2")}}</el-button>
    </div>
  </div>
</template>

<script>
import i18n from "@/lang";
import receiptService from "@/service/receiptService";

export default {
  name: "addReceiptTask",
  props: ["detailData"],
  data() {
    return {
      addForm: {},
      rules: {
        url: [{ required: true, message: i18n.t("valid.URL.NOTNULL") }],
      },
    };
  },
  created() {
    this.addForm = JSON.parse(this.detailData);
    this.addForm.hour1 = 6;
    this.addForm.hour2 = 21;
    // console.log(this.addForm)
  },
  methods: {
    addSubmit() {
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          let params = {
            webid: 0,
            orgid: this.addForm.orgid,
            name: this.addForm.name,
            url: this.addForm.url,
            status: this.addForm.status,
            endtime: this.addForm.endtime,
            hour1: this.addForm.hour1,
            hour2: this.addForm.hour2,
            reportstatus: this.addForm.reportstatus,
          };
          receiptService.addReceipt(params).then((res) => {
            if (res && res.data.result === 0) {
              this.$message.success("操作成功!");
              this.$emit("closeVisible", "add");
            }
          });
        }
      });
    },
    cancel() {
      this.$emit("closeVisible", "cancel");
    },
  },
};
</script>

<style>
.inline {
  display: inline;
}

.add_receipt_task .footer {
  display: flex;
  justify-content: flex-end;
}
.add_receipt_task .form .form_item {
  margin-bottom: 30px;
}
</style>